import { ApiProperty } from '@nestjs/swagger'
import { IsEnum, IsNumber, IsOptional, IsString, Length } from 'class-validator'
import { PagingDto } from 'src/common/dto'
import { StatusEnum } from 'src/common/enum'

export class ListDictType extends PagingDto {
  @IsOptional()
  @IsString({ message: '字典名称必须是字符串' })
  @Length(0, 100)
  dictName?: string

  @IsOptional()
  @IsString({ message: '字典类型必须是字符串' })
  @Length(0, 100)
  dictType?: string

  @IsOptional()
  @IsString()
  @IsEnum(StatusEnum)
  status?: string
}

// 创建数据类型 dto
export class CreateDictTypeDto {
  @ApiProperty({
    required: true,
    description: '数据字典名称'
  })
  @IsString()
  @Length(0, 100)
  dictName: string

  @ApiProperty({
    required: true,
    description: '数据字典类型'
  })
  @IsString()
  @Length(0, 100)
  dictType: string

  @ApiProperty({
    required: true,
    description: '备注'
  })
  @IsOptional()
  @IsString()
  @Length(0, 500)
  remark?: string

  @ApiProperty({
    required: false,
    description: '数据字典状态'
  })
  @IsOptional()
  @IsString()
  @IsEnum(StatusEnum)
  status?: string
}

export class UpdateDictTypeDto extends CreateDictTypeDto {
  @IsNumber()
  dictId: number
}

// 字典列表数据查询 dto
export class ListDictData extends PagingDto {
  @IsOptional()
  @IsString()
  @Length(0, 100)
  dictLabel?: string

  @IsOptional()
  @IsString()
  @Length(0, 100)
  dictType?: string

  @IsOptional()
  @IsString()
  @IsEnum(StatusEnum)
  status?: string
}

/** 创建字典数据 dto */
export class CreateDictDataDto {
  @IsString()
  @Length(0, 100)
  dictType: string

  @IsString()
  @Length(0, 100)
  dictLabel: string

  @IsString()
  @Length(0, 100)
  dictValue: string

  @IsString()
  @Length(0, 100)
  listClass: string

  @IsOptional()
  @IsNumber()
  dictSort?: number

  @IsOptional()
  @IsString()
  @Length(0, 500)
  remark?: string

  @IsOptional()
  @IsString()
  @IsEnum(StatusEnum)
  status?: string
}

// 更新数据字典数据 dto
export class UpdateDictDataDto extends CreateDictDataDto {
  @IsNumber()
  dictCode: number
}
